package com.wlcorp.forcazamis.web.action.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wlcorp.forcazamis.domain.system.Company;
import com.wlcorp.forcazamis.sys.util.ContextUtil;
import com.wlcorp.forcazamis.sys.util.WebUtil;

public class CompanyAction extends DispatchAction {

	public ActionForward companyManager(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		Company company=ContextUtil.getInstance().getCompanyService().getCompany();
		if(null==company){
			company=new Company("", "", "", "", "", "", "", "", "","", "", "", "");
			company.setCompanyId(new Long(0));
		}
		request.setAttribute("company", company);
		return mapping.findForward("manager");
	}

	public ActionForward modifyCompany(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		Company company = new Company();
		WebUtil.setRequestToObject(request,company);
		if(0==company.getCompanyId()){
			ContextUtil.getInstance().getCompanyService().saveCompany(company);
		}else{
			ContextUtil.getInstance().getCompanyService().updateCompany(company);
		}
		request.setAttribute("company", company);
		WebUtil.setAlertMessage(request, "操作成功！");
		return mapping.findForward("manager");
	}

}
